function [p,ai] = prbond(sd,md,rv,cpn,yld,per,basis)
%PRBOND  Price of security with regular periodic interest payments.
%   Returns the price P and accrued interest AI of a security with regular
%   periodic interest payments.
%
%   [P,AI] = PRBOND(SD,MD,RV,CPN,YLD,PER,BASIS)
%
%   Enter dates as serial date numbers or date strings.  This function also
%   applies to zero-coupon bonds or pure discount securities by letting
%   CPN = 0.
%
%   Inputs:
%       SD      -  Settlement date
%       MD      -  Maturity date
%       RV      -  Par Value
%       CPN     -  Coupon Rate
%       YLD     -  Yield
%
%   Optional Inputs:
%
%       per     - the number of coupon periods per year
%                  1 - annual
%                  2 - semi-annual (default)
%                  3 - three times per year
%                  4 - quarterly
%                  6 - bi-monthly
%                 12 - monthly
%
%       basis   -  the day-count basis:
%                  0 = actual/actual (default)
%                  1 = 30/360 SIA
%                  2 = actual/360
%                  3 = actual/365
%                  4 = 30/360 PSA
%                  5 = 30/360 ISDA
%                  6 = 30E/360
%                  7 = actual/365 Japanese
%                  8 - actual/actual ISMA
%                  9 - actual/360 ISMA
%                 10 - actual/365 ISMA
%                 11 - 30/360 ISMA
%                 12 - actual/365 ISDA
%
%   Using the following data,
%
%       SD = '02/01/1960'
%       MD = '01/01/1990'
%       RV = 1000
%       CPN = 0.08
%       YLD = 0.06
%       PER = 2
%       BASIS = 0
%
%   [p,ai] = prbond(sd,md,rv,cpn,yld,per,basis)
%
%   returns p = 1276.39 and ai = 6.81.
%
%   See also YLDBOND, PRMAT, PRDISC.
%
%   Reference: Mayle, Standard Securities Calculation Methods, Volumes
%              I-II, 3rd edition.  Formulas 6, 7.

% Copyright 1995-2006 The MathWorks, Inc.
% $Revision: 1.7.2.8 $ $Date: 2007/11/07 18:29:48 $

% Default day count is actual/actual
if nargin < 7
    basis = 0;
end

% Default number of periods is 2
if nargin < 6
    per = 2;
end

if nargin < 5
    error('finance:prbond:notEnoughInputs',...
        'Missing one of SD, MD, RV, CPN, and YLD.');
end

if any(any(per ~= 0 & per ~= 1 & per ~= 2 & per ~= 3 & ...
        per ~= 4 & per ~= 6 & per ~= 12 ))
    error('finance:prbond:invalidPeriod',...
        'Invalid number of coupon payments specified.');
end


if any(~isvalidbasis(basis))
    error('finance:prbond:invalidBasis',...
        'Invalid day count basis specified.');
end

if any(any(ischar(sd) || ischar(md)))
    sd = datenum(sd);
    md = datenum(md);
end

if length(sd) == 1
    sd = sd*ones(size(md));
end

if length(md) == 1
    md = md*ones(size(sd));
end

if length(rv) == 1
    rv = rv*ones(size(sd));
end

if length(cpn) == 1
    cpn = cpn*ones(size(sd));
end

if length(yld) == 1
    yld = yld*ones(size(sd));
end

if length(per) == 1
    per = per*ones(size(sd));
end

if length(basis) == 1
    basis = basis*ones(size(sd));
end

% check parameter dimensions
if checksiz([size(sd);size(md);size(rv);size(cpn);size(yld);...
        size(per);size(basis)],mfilename)
    return
end

p = zeros(size(sd));
ai = p;

% check boundary range
for i = 1:length(p(:));
    if checkrng(str2mat('sd','md','cpn','yld','per'),...
            [sd(i),md(i),cpn(i),yld(i),per(i)],...
            [-inf sd(i) 0 0 0],[md(i) inf inf inf inf],...
            str2mat('-inf','sd','0','0','0'),...
            str2mat('md','inf','inf','inf','inf'),['l';'e';'e';'e';'l'],...
            ['e';'l';'l';'l';'l'],mfilename)
        return
    end
    if checktyp('per',per(i),'int',mfilename);return;end
end

[p , ai] = bndprice(yld,cpn,sd,md,per,basis,[],[],[],[],[],rv);

% [EOF]
